<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      const arr = [1, 2, 3, 4, 5];

      function map(arr, cb) {
        const newarr = []; // 新数组
        for (let i = 0; i < arr.length; i++) {
          const r = cb(arr[i], i);
          newarr.push(r);
        }
        return newarr; // 返回新数组
      }
      console.log(
        map(arr, function (v, i) {
          return v * 2;
        })
      );
    </script>
  </body>
</html>
